package model.common;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class Common {

	public static Connection conn = null;

	/**
	 * this method used connect to DB
	 * 
	 * @throws SQLException
	 */
	public static void connect() {
		Properties properties = new Properties();

		try {
			properties.load(new FileInputStream("F:\\Eclipse_Project\\MathDict\\src\\conf\\conf.properties"));
			// System.out.println(properties.getProperty("driverName"));
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("Co loi xay ra! Khong load duoc file conf.properties!");
		}

		String driverName = properties.getProperty("driverName");
		String dbURL = properties.getProperty("dbURL");
		String username = properties.getProperty("username");
		String password = properties.getProperty("password");

		try {

			Class.forName(driverName);
			conn = DriverManager.getConnection(dbURL, username, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void disconnect() {
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
